home *** CD-ROM | disk | FTP | other *** search
- # SpecTcl, by S. A. Uhler
- # Copyright (c) 1994-1995 Sun Microsystems, Inc.
- #
- # See the file "license.txt" for information on usage and redistribution
- # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- #
- # get configure info for all of the widgets (Simplified version)
- # The commands in this file are used to derive information about
- # widgets, options, etc. This information needs to be computed once
- # for each version of TK, and is invariant across all applications
-
- # find all tcl commands that are widgets
- # <command> .xxx must work and return .xxx
- # winfo exists .xxx must be true
- # For each widget, extract info into an array
-
- # [This is the *old* tK3.6 version]
-
- proc configure_widget_data {{var Widget_data} {check ._check_} {cmd ""}} {
- upvar $var data
- catch {destroy $check}
-
- # only need to run this 1'ce
- if {[info exists data(widgets)]} {
- return $data(widgets)
- }
- array set skip {
- toplevel 1 exit 1 destroy 1 puts 1 eval 1 menu 1 sh 1 spawn 1
- vwait 1 quit 1
- }
-
- foreach i [info commands] {
- if {[string index $i 0] == "."} continue ;# skip widget inst's
- if {[info exists skip($i)]} continue ;# skip these
- if {[string match exp_* $i]} continue ;# skip these too
- if {[info procs $i] == $i} continue ;# skip procedures
- # if {$i == "text"} {set do "text -font fixed"} {set do $i}
- set do $i
- dputs $i
- if {[catch "$do $check" foo]} continue
- if {[winfo exists $check]} {
- if {$cmd != ""} {
- eval "$cmd $i"
- }
- lappend widgets $i
- fetch_widget_data $i data $check
- }
- catch {destroy $check}
- }
- set data(widgets) $widgets
- return $widgets
- }
-
- # build an array containing widget options
-
- proc fetch_widget_data {widget {array_name Widget_data} {check ._check_}} {
- upvar $array_name data
-
- # query configuration options
-
- set all [$check configure]
- catch {unset data(options:$widget)} ;# incase we re-source
- foreach option $all {
- if {[regexp {^-([^ ]+) [^ ]+ [^ ]+ ([^ ]+) .*} $option x name value]} {
- set data(default:$widget,$name) $value
- dputs "$widget $option"
- lappend data(options:$widget) $name
- if {![info exists data(option:$name)]} {
- set data(option:$name) [get_option_type $check $widget $name]
- }
- }
- }
- return ""
- }
-
- # return the type of an option
- # the only *guaranteed* way to do this is by creating a new widget for
- # each test, as some invalid options leave the widgets in an undefined state
- # Thats too slow, so We'll keep a list of "bad" options and deal with them
- # separately
-
- proc get_option_type {name widget option {font fixed}} {
-
- # try to set the option to these values. Keep track of the values
- # that work.
-
- set tests "2 1 1c #123 ne raised warning arrow disabled vertical $font"
- array set bad_options {image 1 orient 1}
- set bad [expr [info exists bad_options($option)] == 1]
-
- foreach test $tests {
- set result [catch "$name configure -$option $test" _Message]
- append out $result
- if {$result && $bad} {
- destroy $name; $widget $name
- }
- }
- return [assign_option_type $out]
- }
-
- # assign a type to result pattern
- # This depends on the types and order of tests performed in
- # get_option_types
- # pat: The list of successes/failures for each test
-
- proc assign_option_type {pat} {
- switch -exact $pat {
- 00000000000 {set result string}
- 00011111111 {set result distance}
- 00111111111 {set result integer}
- 10111111111 {set result boolean}
- 11101111111 {set result color}
- 11110111111 {set result anchor}
- 11111011111 {set result relief}
- 11111101111 {set result bitmap}
- 11111110111 {set result cursor}
- 11111111011 {set result state}
- 11111111101 {set result orientation}
- 11111111110 {set result font}
- 11111111111 {set result special}
- default {set result unknown}
- }
- return $result
- }
-
- # configure the widget data for the table geometry manager
- # This is hard-wired for now create something to manage, manage it
- # extract the management options, then destroy it.
- # for now, we'll pretend the geometry manager is like a widget,
- # and configure its data the same way This will change with the new
- # table geometry manager
-
- proc configure_geometry_data {{var Widget_data} {check ._check_}} {
- upvar #0 $var data
- frame $check
- frame $check.1
- blt_table $check $check.1 0,0
- regsub -all { -} [blt_table info $check.1] { default:table,} options
- regsub -all pad $options wad options ;# botch for padding
- regsub -all anchor $options align options ;# botch for padding
- destroy $check
- array set data [lrange $options 2 end]
- foreach i {row column} {
- set data(default:position,$i) 0
- }
- }
-